#include <bits/stdc++.h>
using namespace std;
int numberList[200005];
int graph[200005];
bool color[200005];
int length;
int check(int limit){
    int ans = 0;
    for (int i = 0;i <= limit;i++){
        for (int j = i-1;j >= 0;j--){
            if (color[i] == color[j] && numberList[i] == numberList[j]){
                ans += numberList[i];
                break;
            }
        }
    }
    return ans;
}
int main(){
    cin.tie(0);
    cout.tie(0);
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    int times;
    cin >> times;
    for (int k = 0;k < times;k++){
        memset(numberList,0,sizeof(numberList));
        memset(graph,0,sizeof(graph));
        memset(color,0,sizeof(color));
        cin >> length;
        for (int i = 0;i < length;i++){
            cin >> numberList[i];
        }
        for (int i = 0;i < length;i++){
            int s1,s2;
            color[i] = 0;
            s1 = check(i);
            color[i] = 1;
            s2 = check(i);
            if (s1 <= s2){
                color[i] = 1;
            }
            else if(s1 > s2){
                color[i] = 0;
            }
            if (i == length -1)cout << check(length) << endl;
        }
    }
    return 0;
}
